<template>
	<view class="">
		<u-dropdown>
			<u-dropdown-item v-model="value1" title="学年选择" :options="options1"></u-dropdown-item>
			<u-dropdown-item v-model="value2" title="学期选择" :options="options2"></u-dropdown-item>
		</u-dropdown>
		<button type="primary" @click="submit">提交</button>
		<view class="warn">
			{{warn}}
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value1: 2022,
				value2: 1,
				options1: [{
						label: '2021-2022',
						value: 2022,
					},
					{
						label: '2020-2021',
						value: 2021,
					},
					{
						label: '2019-2020',
						value: 2020,
					},
					{
						label: '2018-2019',
						value: 2019,
					}
				],
				options2: [{
						label: '第一学期',
						value: 1,
					},
					{
						label: '第二学期',
						value: 2,
					},
				],
				warn:''
			}
		},
		methods: {
			submit() {
				let that = this;
				uni.request({
					method: 'POST', // 默认GET
					url: `https://wesl.nekolab.tech/v1/table/upload`,
					data: {
						token: uni.getStorageSync('token'),
						year:that.value1,
						term:that.value2,
						username:uni.getStorageSync('jwczh'),
						password:uni.getStorageSync('password')
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					success(res) {
						if(res.data.code!=200){
							that.warn=res.data.msg
						}else{
							uni.switchTab({
								url: '../timetable/timetableInfo',
								success: function(e) {
									var page = getCurrentPages()[0]
									if (page == undefined || page == null) return;
									page.onLoad();
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
	button {
		margin-top: 300rpx;
		width: 50%;
	}
	.warn {
		text-align: center;
		margin-top: 24rpx;
		color: #cc3300;
		font-size: 28rpx;
	}
</style>
